package com.gome.gop.common.exception;

/**
 * 业务异常信息
 *
 * @author user
 *
 */
public class BussinessException extends RuntimeException {
	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 业务数据ID
	 */
	private String id;

	/* 错误状态码 */
	private Integer code;
	/**
	 * 操作人
	 */
	private String userId;

	/**
	 * 请求参数
	 */
	private Object param;

	private BussinessException() {
	}

	/**
	 * @param id
	 *            业务ID
	 * @param userId
	 *            操作用户
	 * @param message
	 *            消息
	 */
	public BussinessException(String id, String userId, String message) {
		super(message);
		this.id = id;
		this.userId = userId;
	}

	public static BussinessException builder(ExceptionMessage message) {
		if (message != null) {
			BussinessException bussinessException = new BussinessException(message.getMessage());
			bussinessException.setCode(message.getCode());
			return bussinessException;
		}
		return new BussinessException();
	}

	public static BussinessException builder(String message) {
		return new BussinessException(message);
	}

	public static BussinessException builder(Integer code, String message) {
		BussinessException bussinessException = new BussinessException(message);
		bussinessException.setCode(code);
		return bussinessException;
	}

	public BussinessException(String message) {
		super(message);
	}

	public BussinessException(String message, Object param) {
		super(message);
		this.param = param;
	}

	public BussinessException(String message, Throwable cause) {
		super(message, cause);
	}

	/**
	 *
	 * @param param
	 *            请求参数
	 * @param id
	 *            业务数据ID
	 * @param userId
	 *            操作人ID
	 * @param message
	 *            消息内容
	 */
	BussinessException(Object param, String id, String userId, String message) {
		super(message);
		this.id = id;
		this.userId = userId;
		this.param = param;
	}

	/**
	 *
	 * @param param
	 *            参数
	 * @param userId
	 *            操作人
	 * @param cause
	 *            异常信息
	 */
	BussinessException(Object param, String userId, Throwable cause) {
		super(cause);
		this.userId = userId;
		this.param = param;
	}

	BussinessException(Object param, String userId, String message, Throwable cause) {
		super(cause);
		this.userId = userId;
		this.param = param;
	}

	public String getId() {
		return id;
	}

	public String getUserId() {
		return userId;
	}

	public Object getParam() {
		return param;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}
}
